package com.wpd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;

import com.common.bo.PageBean;
import com.common.bo.ResultMsg;
import com.common.util.StringUtil;
import com.wpd.bo.WpdUser;
import com.wpd.service.IWpdUserService;

/**
 *
 *  @author : 自动生成
 *  @date   : 2017年07月14日 10:18:16
 *  @desc   : WpdUser转发控制层
 */

@Controller
@RequestMapping("/wpdUser")   
public class WpdUserController {
	 @Autowired
	 private IWpdUserService wpdUserService;
	 
	 /**
	 * 初始化界面
	 * @return
	 */
	@RequestMapping(value = "/wpdUserInit")
	public ModelAndView wpdUserInit() {
		ModelAndView mv = new ModelAndView("wpdUser");
		return mv;
	}
	 
	 /**
	 * 保存WpdUser
	 * 需要参数： wpdUser WpdUser对象
	 */
	@RequestMapping(value="/saveWpdUser")
	@ResponseBody 
	public ResultMsg saveWpdUser(@ModelAttribute WpdUser wpdUser){
		if(StringUtil.isEmpty(wpdUser.getGuid())){
			wpdUserService.insert(wpdUser);
		}else{
			wpdUserService.update(wpdUser);
		}
		return new ResultMsg("0", "成功");
	}
	
	/**
	 * 根据WpdUser传入属性 删除WpdUser对象
	 * 需要参数  wpdUser：WpdUser对象
	 */
	@RequestMapping(value="/deleteWpdUser")  
	@ResponseBody 
	public ResultMsg deleteWpdUser(@ModelAttribute WpdUser wpdUser){
		wpdUserService.delete(wpdUser);
		return new ResultMsg("0", "成功");
	}
	 
	 /**
	  * 获取WpdUser分页列表
	  */
	 @RequestMapping(value="/queryWpdUserPageList", produces = {"application/json;charset=UTF-8"})
	 @ResponseBody
	 public ResultMsg queryWpdUserPageList(
			WpdUser wpdUser,HttpServletRequest request,
			@RequestParam(value="pageSize",required=true) Integer pageSize,
			@RequestParam(value="pageIndex",required=true) Integer pageIndex){
		Integer count = wpdUserService.getTotalCount(wpdUser);
		PageBean pageBean = new PageBean(pageSize, pageIndex);
		List<WpdUser> list = wpdUserService.queryPageList(wpdUser, pageBean);
		Map<String, Object> extraMap = new HashMap<String, Object>();
		extraMap.put("page", pageIndex);
		extraMap.put("pagesize", pageSize);
		extraMap.put("total", count);
		ResultMsg result = new ResultMsg("0", "成功"); 
		result.setData(list);
		result.setExtra(extraMap);
		return result;
	}

	/**
	 * 得到WpdUser对象
	 * 需要参数：  wpdUser：WpdUser对象
	 */
	@RequestMapping(value="/getWpdUser")  
	@ResponseBody 
	public ResultMsg getWpdUser(@ModelAttribute WpdUser wpdUser){
		ResultMsg result = new ResultMsg("0", "成功"); 
		result.setData(wpdUserService.getBean(wpdUser));
		return result;
	}
}
